package com.sixmac.platform.service.impl;

import com.sixmac.core.base.service.BaseService;
import com.sixmac.core.plugins.dao.Blade;
import com.sixmac.core.toolbox.ajax.AjaxResult;
import com.sixmac.module.Installer;
import com.sixmac.module.Landlord;
import com.sixmac.module.Room;
import com.sixmac.platform.service.IndexService;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by admin on 2018/9/5.
 */

@Service
public class IndexServiceImpl extends BaseService<Installer> implements IndexService {

    public AjaxResult recordRoom(String lng, String lat, Integer region, String address, String images, String mobile, String lockNo) {
        Landlord landlord = Blade.create(Landlord.class).findFirstBy("mobile=#{mobile}", getData("mobile", mobile));

        Room r = Blade.create(Room.class).findFirstBy("lockNo=#{lockNo}", getData("lockNo", lockNo));
        if (r != null)
            return error("房间已存在");

        //首先通过手机号码查找房东，如果房东不存在，则提示房东不存在
        if (landlord == null)
            return error("房东不存在");

        Room room = new Room();
        room.setCreateDate(new Date());
        room.setAddress(address);
        room.setLng(lng);
        room.setLat(lat);
        room.setRegion(region);
        room.setImages(images);
        room.setLockNo(lockNo);
        room.setLandlordId(landlord.getId());
        Blade.create(Room.class).save(room);
        return success("绑定成功");
    }
}
